﻿<html>

<head>
${inc:/action/pub/common}
<title>正房小房政策信息</title>

</head>

<body>
<center>
<div id="divForm">
<form name="form1" onsubmit="return insertForm()" action="${def:context}${def:actionroot}/update" 
		method="POST" target="insertFrame">
<input type="hidden" name="policy_tuid" value="${fld:id}">
<table width="100%" class="grid">
 <caption><font size="5"><b>正房小房政策信息表</b></font><br/><br/></caption>
  <tr align="center">
	<th></th>
    <th>房屋类别</th>
    <th>等级</th>
    <th>产权置换价格</th>
    <th>备注说明</th>
  </tr>
 <tbody id="gridBody">
  <rows>
  <tr>
    <td align="center"><img src="${def:context}/images/clear.gif" onclick="deleteRow(this.parentNode.parentNode.sectionRowIndex);" border="0" class="tool" title="删除"></td>
    <td align="center"><input type="hidden" name="house_type" value="${fld:house_type}">
		<select name="h_type" onchange="selectOnchange(this)">
			<option value="">请选择</option>
			<option value="0">&nbsp;正房&nbsp;</option>
			<option value="1">&nbsp;小房&nbsp;</option>
		</select>
	</td>
    <td align="center"><input type="hidden" name="house_level" value="${fld:house_level}">
		<select name="h_level" onchange="selectOnchange(this)">
			<option value="">请选择</option>
			<option value="1">&nbsp;一等&nbsp;</option>
			<option value="2">&nbsp;二等&nbsp;</option>
			<option value="3">&nbsp;三等&nbsp;</option>
			<option value="4">&nbsp;四等&nbsp;</option>
		</select>
	</td>
    <td align="center"><input type="text" name="zhihuan_price" size="10" value="${fld:zhihuan_price}" maxlength="10"></td>

    <td align="center">
		<textarea cols="20" rows="2" name="remark">${fld:remark}</textarea>
	</td>
  </tr>
  </rows>
  <tr>
    <td align="center"><img src="${def:context}/images/clear.gif" onclick="deleteRow(this.parentNode.parentNode.sectionRowIndex);" border="0" class="tool" title="删除"></td>
    <td align="center"><input type="hidden" name="house_type" value="">
		<select name="h_type" onchange="selectOnchange(this)">
			<option value="">请选择</option>
			<option value="0">&nbsp;正房&nbsp;</option>
			<option value="1">&nbsp;小房&nbsp;</option>
		</select>
	</td>
    <td align="center"><input type="hidden" name="house_level" value="">
		<select name="h_level" onchange="selectOnchange(this)">
			<option value="">请选择</option>
			<option value="1">&nbsp;一等&nbsp;</option>
			<option value="2">&nbsp;二等&nbsp;</option>
			<option value="3">&nbsp;三等&nbsp;</option>
			<option value="4">&nbsp;四等&nbsp;</option>
		</select>
	</td>
    <td align="center"><input type="text" name="zhihuan_price" size="10" value="" maxlength="10"></td>

    <td align="center">
		<textarea cols="20" rows="2" name="remark"></textarea>
	</td>
  </tr>
  </tbody>
  <tr>
	<th colspan="12" align="center">
		<input type="submit" value="提交" class="cmd" name="submit"><input type="button" value="添加" onclick="addRow();" class="cmd" name="addBtn"><input type="button" value="返回" onclick="return gotoMaster(true);" class="cmd" name="backBtn">
	</th>
  </tr>
</table>
</form>
<iframe name="insertFrame" style="display:none">
</iframe>
</div>
<div id="divStatus" class="alert" style="text-align:left; display:none;color:gray;width:150px;font-weight:bold;font-family:Arial">
	<img src="${def:context}/images/progress.gif"> 请稍候...
</div>
</center>

</body>

</html>

<script language="javascript">
String.prototype.Trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

function MyCheckMoney(num,obj)
{
    var input = obj.value.Trim();
    var pos1 = input.indexOf(".");
    var pos2 = input.lastIndexOf(".");
    var charset = "1234567890.";
    if ((pos1 != pos2)||(!CheckChar(charset, input, true))) {
        alert ("请输入金额，只可包含数字和一个“.”！");
        obj.focus();
        obj.select();
        return false;
    }
    if(num==null || num=="")
    {
        var output = eval((Math.round(input*100))/100);
        obj.value=output;
    }
    else
    {
        var i_exp=Math.pow(10,num)
        var output = eval((Math.round(input*i_exp))/i_exp);
        obj.value=output;
    }
    return true;
}

//字段校验
function insertForm(){
    //if(CheckNull("user_name","form1")) return false;
    //if(!CheckRadio("is_local","请选择是否为坐地户","","form1")) return false;
	var b = document.getElementById("gridBody");
	if(b.rows.length == 1){
		if(document.forms[0].house_type.value.Trim()==""){
			alert("请选择正房小房！");
			return false;
		}
		if(document.forms[0].house_level.value.Trim()==""){
			alert("请选择等级！");
			return false;
		}
		if(document.forms[0].zhihuan_price.value.Trim()==""){
			alert("产权置换价格不能为空！");
			document.forms[0].zhihuan_price.focus();
			return false;
		}
		if(!MyCheckMoney(2,document.forms[0].zhihuan_price)) return false;

		if(document.forms[0].remark.value.Trim().length()> 120){
			alert("备注信息长度不能大于120，请重新输入！");
			document.forms[0].remark.focus();
			return false;
		}
	}else{
		for (i=0;i<b.rows.length;i++)
		{
			if(document.forms[0].house_type[i].value.Trim()==""){
				alert("请选择正房小房！");
				return false;
			}
			if(document.forms[0].house_level[i].value.Trim()==""){
				alert("请选择等级！");
				return false;
			}
			if(document.forms[0].zhihuan_price[i].value.Trim()==""){
				alert("产权置换价格不能为空！");
				document.forms[0].zhihuan_price[i].focus();
				return false;
			}
			if(!MyCheckMoney(2,document.forms[0].zhihuan_price[i])) return false;

			if(document.forms[0].remark[i].value.Trim().length> 120){
				alert("备注信息长度不能大于120，请重新输入！");
				document.forms[0].remark[i].focus();
				return false;
			}
		}
	}
    document.form1.submit.disabled = true;
	document.form1.addBtn.disabled = true;
	document.form1.backBtn.disabled = true;
	document.getElementById("divStatus").style.display="";
	return true;
}

function insertOK()
{
	document.getElementById("divStatus").style.display="none";	
	document.form1.submit.disabled = false;
	document.form1.addBtn.disabled = false;
	document.form1.backBtn.disabled = false;
	alert("保存成功.");
}

function updateError(msg)
{
	document.getElementById("divStatus").style.display="none";
	document.form1.submit.disabled = false;
	document.form1.addBtn.disabled = false;
	document.form1.backBtn.disabled = false;
	alert(msg);
}

function addRow()
{
	var b = document.getElementById("gridBody");

	var x = b.insertRow(-1);
	
	var d = b.rows[0];

	for (i=0;i<d.cells.length;i++)
	{
		var c = x.insertCell(-1);
		c.innerHTML = d.cells[i].innerHTML;
		c.align = d.cells[i].align;
		c.valign = d.cells[i].valign;
	}
	
	document.forms[0].house_type[b.rows.length-1].value = "";
	document.forms[0].h_type[b.rows.length-1].options[0].selected=true;
	document.forms[0].house_level[b.rows.length-1].value = "";
	document.forms[0].h_level[b.rows.length-1].options[0].selected=true;
	document.forms[0].zhihuan_price[b.rows.length-1].value = "";
	document.forms[0].remark[b.rows.length-1].value = "";
}

function deleteRow(j)
{	
	var b = document.getElementById("gridBody");
	if(b.rows.length==1)
	{
		alert("至少要保留一条信息！");
	}
	else
	{
		b.deleteRow(j);
	}
}

function selectOnchange(obj){
	obj.parentNode.childNodes[0].value = obj.value;
}

window.onload = function(){
	var b = document.getElementById("gridBody");
	var length = b.rows.length;
	if(length > 1){
		deleteRow(length-1);
		if(b.rows.length == 1){
			var val = document.forms[0].house_type.value;
			for(i=0;i<document.forms[0].h_type.options.length;i++){
				if(val == document.forms[0].h_type.options[i].value){
					document.forms[0].h_type.options[i].selected = true;
					break;
				}
			}

			var val2 = document.forms[0].house_level.value;
			for(i=0;i<document.forms[0].h_level.options.length;i++){
				if(val2 == document.forms[0].h_level.options[i].value){
					document.forms[0].h_level.options[i].selected = true;
					break;
				}
			}
		}else{
			for (j=0;j<b.rows.length;j++)
			{
				var val = document.forms[0].house_type[j].value;
				for(i=0;i<document.forms[0].h_type[j].options.length;i++){
					if(val == document.forms[0].h_type[j].options[i].value){
						document.forms[0].h_type[j].options[i].selected = true;
						break;
					}
				}

				var val2 = document.forms[0].house_level[j].value;
				for(i=0;i<document.forms[0].h_level[j].options.length;i++){
					if(val2 == document.forms[0].h_level[j].options[i].value){
						document.forms[0].h_level[j].options[i].selected = true;
						break;
					}
				}
			}
		}
	}
}

function gotoMaster(flag){
	var url = "${def:context}/action/dq/policy/crud";
	if(flag == true){
		if(window.confirm("确定放弃修改？") == true){
			document.location.href = url;
		}
	}else{
		document.location.href = url;
	}
	
}
</script>
    